import Vue from 'vue'
import Vuex from 'vuex'
import * as localStorage from './storage/localStorage'
import * as CommonUtils from '../utils/utils.js'
Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		userInfo: localStorage.userInfo,
		token: localStorage.token,
		tallys:localStorage.tallys,
		tally:localStorage.tally,
	},
	getters: {

	},
	mutations: {
		getStoreStorage(state) {
			for (let i in state) {
				if (state[i].then) {
					Promise.resolve(state[i]).then((value) => {
						console.log(i)
						state[i] = value
					})
				}
			}
		},
		setToken(state, paramArray) {
			let key = 'token' + CommonUtils.getVersionCode();
			uni.setStorageSync(key, paramArray)
			state.token = paramArray
		},
		setTallys(state, paramArray) {
			let key = 'tallys' + CommonUtils.getVersionCode();
			uni.setStorageSync(key, paramArray)
			state.tallys = paramArray
		},
		setTally(state, paramArray) {
			let key = 'tally' + CommonUtils.getVersionCode();
			uni.setStorageSync(key, paramArray)
			state.tally = paramArray
		}

	},
	actions: {

	}
})

export default store